<template>
    <Layout>
        <Form ref="queryParam" :model="queryParam" :label-width="120">
            <Row :gutter="16" class="query-form2" v-show="!switchFlag">
                <Col span="8">
                    <FormItem label="项目名称：" prop="projectName">
                        <Input class="query-form-el" type="text" v-model="queryParam.projectName"></Input>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem label="责任单位：">
                        <Input class="query-form-el" type="text" v-model="queryParam.dutyOrgName"></Input>
                    </FormItem>
                </Col>
                <Col span="8">
                    <div style="float: right;">
                        <Button type="primary" class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
                        <Button @click="reset" class="ivu-btn-reset" style="margin-left: 10px" >重置</Button>
                        <Button @click="switchQuery(true)" style="margin-left: 10px" class="ivu-btn-switch2" type="text" >展开<Icon type="ios-arrow-down"/></Button>
                    </div>
                </Col>
            </Row>
            <Row v-show="switchFlag" class="query-form">
                <Col span="8">
                    <FormItem label="项目名称：" prop="projectName">
                        <Input class="query-form-el" type="text" v-model="queryParam.projectName"></Input>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem label="责任单位：" prop="dutyOrgName">
                        <Input class="query-form-el" type="text" v-model="queryParam.dutyOrgName"></Input>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem label="项目性质：">
                        <Select v-model="queryParam.projectNature">
                            <Option v-for="item in projectNatureMaps" :value="item.codingCodeId" :key="item.codingCodeId">
                                {{item.codingName}}
                            </Option>
                        </Select>
                    </FormItem>
                </Col>
            </Row>
            <Row v-show="switchFlag" class="query-form">
                <Col span="8">
                    <FormItem label="项目级别：">
                        <Select v-model="queryParam.projectLevel">
                            <Option v-for="item in projectLevelMaps" :value="item.codingCodeId" :key="item.codingCodeId">
                                {{item.codingName}}
                            </Option>
                        </Select>
                    </FormItem>
                </Col>
                <Col span="8">
                </Col>
                <Col span="8">
                    <Button @click="switchQuery(false)" class="ivu-btn-switch" type="text">收起∧</Button>
                    <Button @click="reset" class="ivu-btn-reset">重置</Button>
                    <Button class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
                </Col>
            </Row>
            <Row class="query-form">
                <Col span="24">
                    <Button size="large" class="ivu-btn-add" icon="md-add" @click="addInfo">新增</Button>
                </Col>
            </Row>
        </Form>

        <Table ref='table' :height="tableHeight" :loading="loading" @on-selection-change='getSelectRows'
               border :columns="columns1" :data="dataTable">
        </Table>

        <Row style="margin-right:10px;">
            <Col span="24">
                <Page style="float: right" :total="pagedata.total" :page-size="pagedata.pageSize"
                      @on-change="pageChange" @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray"
                      show-total show-sizer show-elevator/>
            </Col>
        </Row>

        <Modal :title="titleName" :transfer=false v-model="modal1" :width=900 
            class-name='limit-height-dialog' :styles="{height:'500px'}" @on-cancel="onCancel">
            <Row>
                <Col span="24">
                    <Form ref="form1" :model="form1" :rules="ruleCustom" label-position="top">
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label="项目名称：" prop="projectName">
                                    <Input type="text" v-model="form1.projectName"></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label="项目基本情况：" prop="projectDesc">
                                    <Input type="textarea" :autosize="true" v-model="form1.projectDesc"></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="责任单位：" prop="dutyOrgId">
                                    <cascaderDom ref="existOrg" @setOrgInfo="setOrgInfo"
                                    :currentOrgName="form1.dutyOrgName"
                                    :currentOrgId="form1.dutyOrgId"
                                    :setCurrentName="{value:form1.dutyOrgId, label:form1.dutyOrgName}" :orgTree="true" :rootOrgId="rootOrgId"></cascaderDom>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label="项目设计单位：" prop="designUnit">
                                    <Input type="text" v-model="form1.designUnit"></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="项目性质：" prop="projectNature">
                                     <Select v-model="form1.projectNature">
                                        <Option v-for="item in projectNatures" :value="item.codingCodeId" :key="item.codingCodeId">
                                            {{item.codingName}}
                                        </Option>
                                    </Select>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label="项目级别：" prop="projectLevel">
                                    <Select v-model="form1.projectLevel">
                                        <Option v-for="item in projectLevels" :value="item.codingCodeId" :key="item.codingCodeId">
                                            {{item.codingName}}
                                        </Option>
                                    </Select>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="所在行政区域：" prop="administrativeMap">
                                    <Cascader :data="tempAreaTree" v-model="form1.administrativeMapArr" change-on-select :transfer="true"
                                              :load-data="areaTreeLoadData" :render-format="labels=>labels.join('·')"  :clearable='false'
                                        @on-change="(value,selectedData)=>{$set(form1,'administrativeMap',value.join(','))}"></Cascader>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label="立项时间：" prop="establishmentTime">
                                    <DatePicker type="date" placeholder="选择时间" v-model="form1.establishmentTime" style="width: 100%"></DatePicker>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="计划开工时间：" prop="startTime">
                                    <DatePicker type="date" placeholder="选择时间" v-model="form1.startTime" style="width: 100%"></DatePicker>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label="计划完工时间：" prop="endTime">
                                    <DatePicker type="date" placeholder="选择时间" v-model="form1.endTime" style="width: 100%"></DatePicker>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="总投资（万元）：" prop="totalInvestment">
                                    <InputNumber :min="0" v-model="form1.totalInvestment" style="width: 100%;"></InputNumber>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label="年综合能源消耗量（吨标准煤）：" prop="powerConsumption">
                                    <InputNumber :min="0" v-model="form1.powerConsumption" style="width: 100%;"></InputNumber>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="项目负责人：" prop="projectLeader">
                                    <Input v-model="form1.projectLeader" type="text"/>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label="联系电话：" prop="contactPhone">
                                    <Input v-model="form1.contactPhone" type="text"/>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label="三同时类型：" prop="projectType">
                                    <CheckboxGroup v-model="form1.projectType">
                                        <Checkbox label="1" >环保水保三同时</Checkbox>
                                        <Checkbox label="2" >职业卫生三同时</Checkbox>
                                        <Checkbox label="3" >安全三同时</Checkbox>
                                        <Checkbox label="4" >节能评估三同时</Checkbox>
                                        <Checkbox label="5" >消防三同时</Checkbox>
                                    </CheckboxGroup>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label="备注：" prop="remark">
                                    <Input v-model="form1.remark" type="textarea"/>
                                </FormItem>
                            </Col>
                        </Row>
                    </Form>
                </Col>
            </Row>
            <div slot="footer">
                <Button @click="submit('form1')" class="ivu-btn-save" :loading="buttonLoading">确定</Button>
                <Button @click="onCancel" class="ivu-btn-cancel">取消</Button>
            </div>
        </Modal>
        <Modal title="三同时详情" class="modal-view-detail" 
              :styles="{height:'500px'}":transfer=false v-model="modal2" :width=900>
            <Row>
                <Col span="24">
                    <Form :model="showdata" :label-width="160">
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label="项目名称：" prop="projectName">
                                     {{showdata.projectName}}
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label="项目基本情况：" prop="projectDesc">
                                    {{showdata.projectDesc}}
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="责任单位：" prop="dutyOrgId">
                                     {{showdata.dutyOrgName}}
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label="项目设计单位：" prop="designUnit">
                                     {{showdata.designUnit}}
                                </FormItem>
                            </Col>                        
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="项目性质：" prop="projectNature">
                                      {{showdata.projectNatureName}}
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label="项目级别：" prop="projectLevel">
                                     {{showdata.projectLevelName}}
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="所在行政区域：" prop="administrativeMap">
                                     {{areaCodeToAreaName(showdata.administrativeMap)}}
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label="立项时间：" prop="establishmentTime">
                                    {{showdata.establishmentTimeStr}}
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="计划开工时间：" prop="startTime">
                                     {{showdata.startTimeStr}}
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label="计划完工时间：" prop="endTime">
                                     {{showdata.endTimeStr}}
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="总投资（万元）：" prop="totalInvestment">
                                     {{showdata.totalInvestment}}
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label="年综合能源消耗量（吨标准煤）：" prop="powerConsumption">
                                     {{showdata.powerConsumption}}
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="项目负责人：" prop="projectLeader">
                                     {{showdata.projectLeader}}
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label="联系电话：" prop="contactPhone">
                                    {{showdata.contactPhone}}
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label="三同时类型：" prop="projectType">
                                    <CheckboxGroup v-model="showdata.projectType">
                                        <Checkbox label="1" disabled>环保水保三同时</Checkbox>
                                        <Checkbox label="2" disabled>职业卫生三同时</Checkbox>
                                        <Checkbox label="3" disabled>安全三同时</Checkbox>
                                        <Checkbox label="4" disabled>节能评估三同时</Checkbox>
                                        <Checkbox label="5" disabled>消防三同时</Checkbox>
                                    </CheckboxGroup>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label="备注：" prop="remark">
                                    {{showdata.remark}}
                                </FormItem>
                            </Col>
                        </Row>
                    </Form>
                </Col>
            </Row>
            <div slot="footer">
                <Button class='ivu-btn-save' @click="modal2=false">关闭</Button>
            </div>
        </Modal>
    </layout>
</template>

<script>
    import {Api} from '../../../api/index.js'
    import cascaderDom from '../../../components/cascader-dom'
    import { mapState, mapGetters, mapActions } from 'vuex'
    import {sessionStorage} from '../../../common/cacheUtils.js';
    import pageCommonFunction from '@/components/pageCommonFunction.js'

    export default {
        components: {
            cascaderDom
        },
        data() {
            return {
                tempAreaTree:[],
                queryParam: {projectName:"",dutyOrgName:'',projectLevel:'',projectNature:''},
                buttonLoading:false,
                form1:{},
                isUpdate:false,
                switchFlag: false,
                projectLevelMaps:{},
                projectNatureMaps:{},
                projectNatures:[],
                projectLevels:[],
                projectNatures:[],
                pageSizeArray: [10, 20, 50],
                pagedata: {
                    total: 0,
                    pageSize: 10,
                    currentPage: 1,
                },
                columns1: [
                    {
                        title: "序号",
                        width: 80,
                        align: "center",
                        fixed: 'left',
                        render: (h, params) => {
                            return h('span', params.index + (this.pagedata.currentPage - 1) * this.pagedata.pageSize + 1);
                        }
                    },
                    {
                        minWidth: 220,
                        title: '项目名称',
                        key: 'projectName',
                        align: 'center'
                    },
                    {
                        minWidth: 220,
                        title: '责任单位',
                        key: 'dutyOrgName',
                        align: 'center'
                    },
                    {
                        minWidth: 220,
                        title: '项目设计单位',
                        key: 'designUnit',
                        align: 'center'
                    },
                     {
                        minWidth: 220,
                        title: '项目性质',
                        key: 'projectNature',
                        align: 'center',
                        render:(h, params)=>{
                            return h('span', this.projectNatureMaps && this.projectNatureMaps[params.row.projectNature] && this.projectNatureMaps[params.row.projectNature].codingName)
                        },
                    },
                    {
                        minWidth: 220,
                        title: '项目级别',
                        key: 'projectLevel',
                        align: 'center',
                        render:(h, params)=>{
                            return h('span', this.projectLevelMaps && this.projectLevelMaps[params.row.projectLevel] && this.projectLevelMaps[params.row.projectLevel].codingName)
                        },
                    },
                    {
                        minWidth: 220,
                        title: '所在行政区域',
                        key: 'administrativeMap',
                        align: 'center',
                        render: (h, params) =>{ 
                            return h('span', this.areaCodeToAreaName(params.row.administrativeMap)); 
                        },
                    },
                    {
                        minWidth: 220,
                        title: '总投资（万元）',
                        key: 'totalInvestment',
                        align: 'center'
                    },
                    {
                        minWidth: 220,
                        title: '年综合能源消耗量（吨标准煤）',
                        key: 'powerConsumption',
                        align: 'center'
                    },
                    {
                        minWidth: 220,
                        title: '立项时间',
                        key: 'establishmentTime',
                        align: 'center',
                        render: (h, params) => {
                            return h('span', this.formatDate(new Date(params.row.establishmentTime),"yyyy-MM-dd"));
                        }
                    },
                    {
                        minWidth: 130,
                        title: '计划开工时间',
                        key: 'startTime',
                        align: 'center',
                        render: (h, params) => {
                            return h('span', this.formatDate(new Date(params.row.startTime),"yyyy-MM-dd"));
                        }
                    },
                    {
                        minWidth: 130,
                        title: '计划完工时间',
                        key: 'endTime',
                        align: 'center',
                        render: (h, params) => {
                            return h('span', this.formatDate(new Date(params.row.endTime),"yyyy-MM-dd"));
                        }
                    },
                    {
                        minWidth: 130,
                        title: '环境',
                        key: 'checkCycle',
                        align: 'center',
                        render: (h, params) => {
                             return h('span', params.row.isEnvironmental=='1'?'√':'×');
                        }
                    },
                    {
                        minWidth: 130,
                        title: '职业卫生',
                        key: 'health',
                        align: 'center',
                        render: (h, params) => {
                            return h('span', params.row.isHealth=='1'?'√':'×');
                        }
                    },
                    {
                        minWidth: 130,
                        title: '安全',
                        key: 'safe',
                        align: 'center',
                        render: (h, params) => {
                            return h('span', params.row.isSafe=='1'?'√':'×');
                        }
                    },
                    {
                        minWidth: 130,
                        title: '节能评估',
                        key: 'energySaving',
                        align: 'center',
                        render: (h, params) => {
                            return h('span', params.row.isEnergy=='1'?'√':'×');
                        }
                    },
                    {
                        minWidth: 130,
                        title: '消防',
                        key: 'fireProtection',
                        align: 'center',
                        render: (h, params) => {
                            return h('span', params.row.isFire=='1'?'√':'×');
                        }
                    },
                    {
                        minWidth: 130,
                        title: '联系电话',
                        key: 'contactPhone',
                        align: 'center'
                    },
                    {
                        title: '操作',
                        key: 'action',
                        fixed: 'right',
                        minWidth: 200,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('A', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        fontSize: '14px',
                                    },
                                    on: {
                                        click: () => {
                                            this.dataTable.forEach((items)=>{      //先取消所有对象的勾选，checkBox设置为false
                                                this.$set(items,'checkBox',false)
                                            });
                                            this.dataTable[params.index].checkBox = true;  //再将勾选的对象的checkBox设置为true
                                            this.viewInfo(params.row);
                                        }
                                    }
                                }, '详情'),
                                h('Divider', {
                                    props: {
                                        type: 'vertical',
                                    }
                                }, ''),
                                h('A', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        fontSize: '14px',
                                        color: (this.currentUserId != params.row.createUserId&&this.loginId != this.Common.admin) && (sessionStorage('userId').getObject('userId').userRole.find(obj => obj.roleId == '73b38b37dff64392ba0ee7dd579bf293') == undefined)  ? '#d0d0d0':'',
                                        pointerEvents:  (this.currentUserId != params.row.createUserId &&this.loginId != this.Common.admin) && (sessionStorage('userId').getObject('userId').userRole.find(obj => obj.roleId == '73b38b37dff64392ba0ee7dd579bf293') == undefined) ? 'none':''
                                    },
                                    on: {
                                        click: () => {
                                            this.updateInfo(params.row);
                                        }
                                    }
                                }, '修改'),
                                h('Divider', {
                                    props: {
                                        type: 'vertical',
                                    }
                                }, ''),
                                h('A', {
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    style: {
                                        fontSize: '14px',
                                         color: (this.currentUserId != params.row.createUserId &&this.loginId != this.Common.admin) && (sessionStorage('userId').getObject('userId').userRole.find(obj => obj.roleId == '73b38b37dff64392ba0ee7dd579bf293') == undefined) ? '#d0d0d0':'red',
                                         pointerEvents:  (this.currentUserId != params.row.createUserId &&this.loginId != this.Common.admin) && (sessionStorage('userId').getObject('userId').userRole.find(obj => obj.roleId == '73b38b37dff64392ba0ee7dd579bf293') == undefined) ? 'none':''
                                    },
                                    on: {
                                        click: () => {
                                            this.deleteInfo(params.row);
                                        }
                                    }
                                }, '删除')
                            ]);
                        }
                    }
                ],
                ruleCustom: {
                    projectName: [{required: true, message: '  ', trigger: 'blur,change'}],
                    dutyOrgId: [{required: true, message: '  ', trigger: 'blur,change'}],
                    designUnit: [{required: true, message: '  ', trigger: 'blur'}],
                    projectLevel: [{required: true, message: '  ', trigger: 'blur'}],
                    projectNature:[{required: true, message: '  ', trigger: 'blur'}],
                    establishmentTime: [{required: true, message: '  ', trigger: 'change',pattern: /.+/}],
                    startTime: [{required: true, message: '  ', trigger: 'change',pattern: /.+/}],
                    endTime: [{required: true, message: ' ', trigger: 'change',pattern: /.+/}],
                    totalInvestment: [{
                        validator: (rule, value, callback) => {
                            if (this.form1.totalInvestment == 0) {
                            callback(' ')
                            } else {
                            callback()
                            }
                        },
                        required: true, message: '  ',type:'number', trigger: 'change'}],
                    projectLeader: [{required: true, message: '  ', trigger: 'blur'}],
                    contactPhone: [{required: true, message: '  ', trigger: 'blur'}],
                    projectType: [{ validator: (rule, value, callback) => {
                            if (value == null || value == '' || value == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },required: true, message: '  ', trigger: 'change'}]
                },
                modal1: false,
                modal2: false,
                add: false,
                titleName:'',
                loading: false,
                tableHeight: '',
                dataTable: [],
                showdata:{},
                currentUser: sessionStorage('userId').getObject('userId'),
                currentUserId: sessionStorage('userId').getObject('userId').userId,
                rootOrgId:''
            }
        },
        async mounted(){
            this.rootOrgId =  sessionStorage('userId').getObject('userId').companyId;
            this.tableHeight = window.innerHeight - this.$refs.table.$el.offsetTop - 145;
            await this.$store.dispatch('trhg/area/query', {scope:this}, { root: true });
            this.$http.get(Api.queryCodeDetailBySortId + '/STS-000001', {params: {}}).then((res) => {
                this.projectLevelMaps = this.dictListToMap(res.data.data);
                this.projectLevels = res.data.data;
            });
            this.$http.get(Api.queryCodeDetailBySortId + '/STS-000002', {params: {}}).then((res) => {
                this.projectNatureMaps = this.dictListToMap(res.data.data);
                this.projectNatures = res.data.data;
            });
            this.query();
            this.tempAreaTree = this.areaTreeMap['0']
        },
        computed:{
            ...mapState('trhg', {
                // areaTree: state => state.area.areaTree?state.area.areaTree:[],
                areaMap: state => state.area.areaMap?state.area.areaMap:[],
                areaTreeMap: state => state.area.areaTreeMap?state.area.areaTreeMap:[],
            }),
        },
        methods: {
            ...pageCommonFunction,
            query(){
                this.loading = true;
                let user = sessionStorage('userId').getObject('userId');
                let data = {
                    startPage: this.pagedata.currentPage,
                    size: this.pagedata.pageSize,
                    companyId: user.companyId
                }
                data = Object.assign(data,JSON.parse(JSON.stringify(this.queryParam)));
                this.$http.get(Api.threeSimProjectList, {
                    params: data
                }).then(function(res){
                    if(res.data.status == 200){
                        this.dataTable = res.data.data.data;
                        this.pagedata.total = res.data.data.totalSize;
                    }
                    this.loading = false;
                }, function(res){
                    this.$Message.error('请求失败');
                    this.loading = false;
                });
            },
            submit(name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        this.form1.isEnvironmental = '0';
                        this.form1.isHealth = '0';
                        this.form1.isSafe = '0';
                        this.form1.isEnergy = '0';
                        this.form1.isFire = '0';
                        this.form1.projectType.forEach(item=>{
                            if(item == '1')
                                this.form1.isEnvironmental = '1'
                            if(item == '2')
                                this.form1.isHealth = '1'
                            if(item == '3')
                                this.form1.isSafe = '1'
                            if(item == '4')
                                this.form1.isEnergy = '1'
                            if(item == '5')
                                this.form1.isFire = '1'                                
                        })
                        this.buttonLoading = true
                        if (this.isUpdate) {
                            let url = Api.threeSimProject
                            this.$http.put(url, this.form1).then((res) => {
                                if(res.data.status == 200){
                                    this.$Message.success('成功');
                                    this.query()
                                    this.buttonLoading = false
                                    this.modal1 = false
                                }else{
                                    this.$Message.error('请求失败');
                                }
                            }).catch(e => {
                                this.$Message.error('请求失败');
                            })
                        } else {
                            let url = Api.threeSimProject;
                            this.$http.post(url, this.form1).then((res) => {
                                if(res.data.status == 200){
                                    this.$Message.success('成功');
                                    this.query()
                                    this.buttonLoading = false
                                    this.modal1 = false
                                }else{
                                    this.$Message.error('请求失败');
                                }
                            }).catch(e => {
                                this.$Message.error('请求失败');
                            })
                        }
                    }else {
                          this.$Message.error('请填报完整!');
                      }
                })
            },
            pageSizeChange(pageSize){
                this.pagedata.pageSize = pageSize;
                this.query();
            },
            pageChange(pageNum){
                this.pagedata.currentPage = pageNum;
                this.query();
            },
            reset(){
                this.queryParam =  {projectName:"",dutyOrgName:'',projectLevel:'',projectNature:''}
                this.query();
            },
            onCancel(){
                this.modal1 = false;
            },
            setOrgInfo(data){
                this.form1.dutyOrgId = data[data.length - 1];
            },
            switchQuery(flag){
                this.switchFlag = flag;
                if (!this.switchFlag) {
                    this.tableHeight = this.tableHeight + 44;
                } else {
                    this.tableHeight = this.tableHeight - 44;
                }
            },
            addInfo(){
                this.isUpdate = false;
                this.modal1 = true;
                this.buttonLoading = false;
                this.titleName = "新增";
                this.form1 = {
                    totalInvestment:0,
                    powerConsumption:0,
                    createUserId: this.currentUser.userId,
                    createOrgId:this.currentUser.orgInfo.orgId,         
                    createDate: new Date(),
                    createDateStr: this.formatDate(new Date()),
                    bsflag:'0'
                };
                setTimeout(() => {
                    this.$refs.existOrg.setCurrentOrg();
                }, 100);
            },
            updateInfo(row){
                this.isUpdate = true;
                this.buttonLoading = false;
                this.form1 = JSON.parse(JSON.stringify(row));
                this.form1.projectType = [];
                if( this.form1.isEnergy == '1')
                    this.form1.projectType.push('4')
                if( this.form1.isEnvironmental == '1')
                    this.form1.projectType.push('1')
                if( this.form1.isHealth == '1')
                    this.form1.projectType.push('2')
                if( this.form1.isSafe == '1')
                    this.form1.projectType.push('3')
                if( this.form1.isFire == '1')
                    this.form1.projectType.push('5')
                this.form1.updateOrgId = this.currentUser.orgInfo.orgId,
                this.form1.updateUserId = this.currentUser.userId;
                this.form1.updateDate = new Date();
                if(this.form1.administrativeMap != null){
                    this.form1.administrativeMapArr = this.form1.administrativeMap.split(',');
                    this.form1.companyAddressName = this.areaCodeToAreaName(this.form1.administrativeMap)
                } else{
                    this.form1.administrativeMapArr = [];
                }
                this.titleName = "修改";
                setTimeout(() => {
                    this.$refs.existOrg.setCurrentOrg();
                }, 100);
                this.modal1 = true;
                this.afterDataToViewInit( this.form1)
            },
            async afterDataToViewInit(data) {
                if (data && data.administrativeMap) {
                    let companyAddressArr = data.administrativeMap.split(',')
                    this.tempAreaTree = []
                    setTimeout(() => {
                        this.tempAreaTree = this.addressEditArr(this.areaTreeMap,companyAddressArr)
                    }, 100)
                }
            },
            viewInfo(row){
                this.showdata = row;
                this.showdata.projectType = [];
                if( this.showdata.isEnergy == '1')
                    this.showdata.projectType.push('4')
                if( this.showdata.isEnvironmental == '1')
                    this.showdata.projectType.push('1')
                if( this.showdata.isHealth == '1')
                    this.showdata.projectType.push('2')
                if( this.showdata.isSafe == '1')
                    this.showdata.projectType.push('3')
                if( this.showdata.isFire == '1')
                    this.showdata.projectType.push('5')
                this.showdata.establishmentTimeStr = this.formatDate(new Date(this.showdata.establishmentTime),"yyyy-MM-dd");
                this.showdata.startTimeStr = this.formatDate(new Date(this.showdata.startTime),"yyyy-MM-dd");
                this.showdata.endTimeStr = this.formatDate(new Date(this.showdata.endTime),"yyyy-MM-dd");
                if(this.projectNatureMaps && this.showdata.projectNature){
                    this.showdata.projectNatureName = this.projectNatureMaps[this.showdata.projectNature].codingName;
                }
                if(this.projectLevelMaps && this.showdata.projectLevel){
                    this.showdata.projectLevelName = this.projectLevelMaps[this.showdata.projectLevel].codingName;
                }
                this.modal2 = true;
            },
            setOrgId(data) {
                this.dataToQuery.orgId= data[data.length - 1];
            },
            setOrgName(data) {
                this.dataToQuery.orgName = data;
            },
            deleteInfo(row){
                this.$Modal.confirm({
                    title: '数据删除',
                    content: '<p>确定删除该条信息</p>',
                    okText: '确认',
                    onOk: () => {
                        this.$http.delete(Api.threeSimProject + "/" + row.projectId, {params:{
                                updateUserId: this.currentUser.userId
                            }}).then((res) => {
                            this.$Message.success({content:'删除成功',duration: 4});
                            this.query();
                        })
                    },
                    cancelText: '取消'
                });
            },
            queryProjectNatureList(){
                this.$http.get(Api.projectNatureMaps).then((res) => {
                    if(res.data.status == 200){
                        this.projectNatureMaps = res.data.data;
                    }
                }).catch(e => {
                    this.$Message.error("附件删除失败");
                });
            },
            queryProjectLevelList(){
                this.$http.get(Api.projectLevelMaps).then((res) => {
                    if(res.data.status == 200){
                        this.projectLevelMaps = res.data.data;
                    }
                }).catch(e => {
                    this.$Message.error("附件删除失败");
                });
            },
            formatDate(date, fmt) {
                if (typeof date == 'string') {
                    return date;
                }
                if (!fmt) fmt = "yyyy-MM-dd hh:mm:ss";
                if (!date || date == null) return null;
                let o = {
                    'M+': date.getMonth() + 1, // 月份
                    'd+': date.getDate(), // 日
                    'h+': date.getHours(), // 小时
                    'm+': date.getMinutes(), // 分
                    's+': date.getSeconds(), // 秒
                    'q+': Math.floor((date.getMonth() + 3) / 3), // 季度
                    'S': date.getMilliseconds() // 毫秒
                }
                if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
                for (let k in o) {
                    if (new RegExp('(' + k + ')').test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
                }
                return fmt
            },
            uuid() {
                let s = [];
                let hexDigits = "0123456789abcdef";
                for(let i = 0; i < 32; i++) {
                    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
                }
                s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
                s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
                let uuid = s.join("");
                return uuid
            },
        }
    }
</script>